﻿//------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2010 , Jirisoft , Ltd. 
//------------------------------------------------------------

namespace DotNet.Business
{
    using DotNet.DbUtilities;
    using DotNet.Model;
    using DotNet.Utilities;
    using DotNet.Manager;

    /// <remarks>
    ///	BaseDelegationManager
    /// 委托代理
    ///	
    ///	修改记录
    /// 
    ///     2008.06.17 版本：1.0 JiRiGaLa  创建。
    ///		
    /// 版本：1.0
    /// </remarks>
    /// <author>
    ///		<name>JiRiGaLa</name>
    ///		<date>2008.06.17</date>
    /// </author> 
    /// </remarks>
    public class BaseDelegationManager : BaseManager
    {
        public BaseDelegationManager()
        {
            base.CurrentTableName = BaseDelegationTable.TableName;
        }

        public BaseDelegationManager(IDbHelper dbHelper) : this()
        {
            DbHelper = dbHelper;
        }

        public BaseDelegationManager(BaseUserInfo userInfo) : this()
        {
            UserInfo = userInfo;
        }

        public BaseDelegationManager(IDbHelper dbHelper, BaseUserInfo userInfo) : this(dbHelper)
        {
            UserInfo = userInfo;
        }

        /// <summary>
        /// 添加委托
        /// </summary>
        /// <param name="consignerID">委托人</param>
        /// <param name="delegantID">受托人</param>
        /// <returns>主键</returns>
        public string Add(string consignerId, string delegantId)
        {
            BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper);
            string sequence = sequenceManager.GetSequence(BaseDelegationTable.TableName);
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
            sqlBuilder.BeginInsert(BaseDelegationTable.TableName);
            sqlBuilder.SetValue(BaseDelegationTable.FieldId, sequence);
            sqlBuilder.SetValue(BaseDelegationTable.FieldConsignerId, consignerId);
            sqlBuilder.SetValue(BaseDelegationTable.FieldDelegantId, delegantId);
            sqlBuilder.SetValue(BaseDelegationTable.FieldCreateUserId, UserInfo.Id);
            sqlBuilder.SetDBNow(BaseDelegationTable.FieldCreateDate);
            return sqlBuilder.EndInsert() > 0 ? sequence : string.Empty;
        }
    }
}